package com.baizhi.cmfzmanager.controller;

import com.baizhi.cmfzmanager.entity.Album;
import com.baizhi.cmfzmanager.service.AlbumService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class AlbumController {

    @Autowired
    private AlbumService albumService;

    @RequestMapping("/getAlbums")
    public Map getAlbums(int page,int rows){
        return albumService.getAlbums(page,rows);
    }

    @RequestMapping("/updatealbum")
    public Map update(Album album){
        Map map = new HashMap();
        try {
            albumService.update(album);
            map.put("message","修改成功！！");
        } catch (Exception e) {
            e.printStackTrace();
            map.put("message","修改失败！！");
        }
        return map;
    }
    @RequestMapping("/addalbum")
    public Map add(Album album){
        Map map = new HashMap();
        try {
            albumService.add(album);
            map.put("message","修改成功！！");
        } catch (Exception e) {
            e.printStackTrace();
            map.put("message","修改失败！！");
        }
        return map;
    }
    @RequestMapping("/deletealbum")
    public Map delete(int[] ids){
        Map map = new HashMap();
        try {
            albumService.delete(ids);
            map.put("message","修改成功！！");
        } catch (Exception e) {
            e.printStackTrace();
            map.put("message","修改失败！！");
        }
        return map;
    }

    @RequestMapping("/getAllAlbum")
    public List<Album> getAllAlbum(){
        return albumService.getAll();
    }
}
